package main

import "fmt"
//棋盘存点，稀疏数组保存的点位置
type Node struct {
	row int
	col int
	val int
}

func main() {
	var arr [11][11]int
	arr[1][2] = 1
	arr[2][3] = 2
	arr[5][2] = 1

	for _, v := range arr {
		for _, v2 := range v {
			fmt.Printf("%d\t", v2)
		}
		fmt.Println()
	}

	var sparseArr []Node

	nodeIndex := Node{
		row: 11,
		col: 11,
		val: 0,
	}
	sparseArr = append(sparseArr, nodeIndex)

	for i, v := range arr {
		for j, v2 := range v {
			if v2 != 0 {
				n := Node{
					row: i,
					col: j,
					val: v2,
				}
				sparseArr = append(sparseArr, n)
			}
		}
	}

	fmt.Println("保存的稀疏数组是:::::")

	for i, v := range sparseArr {
		fmt.Printf("%d %d %d %d\n", i, v.row, v.col, v.val)
	}

}
